@echo off
chcp 65001
rem 杀死进程
echo "----------------------------------------关闭工具箱服务----------------------------------------"
wmic process Where name="zxw-aj-tools.exe" call terminate

rem 启动窗口
rem explorer .

set programPath="%cd%\zxw-aj-tools.exe"

rem 程序标准大小 80mb
set standardSize=83886080
rem 当前程序大小
set size=0

rem 校验文件是否存在
if exist %programPath% (
	echo "----------------------------------------获取程序大小----------------------------------------"
	for %%A in (%programPath%) do set size=%%~zA
)

if %size% gtr %standardSize% (
	echo "----------------------------------------程序正常，执行备份----------------------------------------"
	copy %programPath% "%cd%\zxw-aj-tools_bak.exe"
	echo "----------------------------------------备份完成，中断更新，可从备份恢复----------------------------------------"
) else (
	echo "----------------------------------------程序异常，等待更新----------------------------------------"
)


rem 下载最新版本exe
echo "----------------------------------------更新工具箱服务----------------------------------------"
curl -o %programPath% "http://tool.zjh336.cn/uploadPath/autoJsTools/webCommonPath/newVersion/zxw-aj-tools.exe"

echo "----------------------------------------更新完成等待启动----------------------------------------"


echo "----------------------------------------正在启动工具箱服务----------------------------------------"
timeout /t 2 > nul

rem 启动服务
start zxw-aj-tools.exe

timeout /t 3 > nul

REM 关闭窗口
exit